package com.googlecode.gwt_control.client.form;

import com.googlecode.gwt_control.client.AbstractViewPart;
import com.googlecode.gwt_control.client.Controller;

/**
 *
 * @author Olafur Gauti Gudmundsson
 */
public abstract class FormWidget extends AbstractViewPart {

    protected final FieldPanel fieldPanel;

    public FormWidget( Controller c ) {
        super(c);
        fieldPanel = new FieldPanel();

        initWidget(fieldPanel);
    }

    protected FieldSection addSection( String title ) {
        return addSection(title, "");
    }

    protected FieldSection addSection( String title, String description ) {
        return fieldPanel.addSection(title, description);
    }

    public boolean isValid() {
        return fieldPanel.isValid();
    }

    public void registerFieldChangeListener( FieldChangeListener listener ) {
        if ( fieldPanel != null ) {
            fieldPanel.addFieldChangeListener(listener);
        }
    }

    public abstract void updateModel();
}
